public class Solution1 {
    public boolean isHappy(int n) {
        int slow = n;
        int fast = pow(n);
        while(slow!=fast) {
            slow = pow(slow);
            fast = pow(pow(fast));
        }
        return slow==1;
    }
    //求每一位数的平方和
    public int pow(int n) {
        int sum =0;
        while(n!=0) {
            int t = n%10;
            sum+=t*t;
            n/=10;
        }
        return sum;
    }
}
